package com.magenta.maxoptra.gis;

import java.util.List;

import static com.magenta.maxoptra.gis.GISFieldType.*;

/**
 * User: KuznetsovD
 * Date: 25.10.11
 * Time: 16:14
 */
public enum GeobaseAttribute implements GISAccountProperty, GISAccountPropertyWithVariant  {

    UseProvider(GisParameter.use_map_provider, MapProviderType.geobase, GISFieldType.BOOLEAN, "false", true, true, 0L),
    GeobaseServerIp(GisParameter.server_ip, MapProviderType.geobase, TEXT, "10.11.13.31", true, 1L),
    GeobaseWsdlLocation(GisParameter.wsdl_location, MapProviderType.geobase, TEXT, "http://10.11.13.31/WebService/GeoBase.asmx?WSDL", true, 2L),
    GeobaseUseCustomGeoAddressForm(GisParameter.use_custom_geo_address_form, MapProviderType.geobase, BOOLEAN, "true", true, 3L),
    GeobaseRegion(GisParameter.region, MapProviderType.geobase, GISFieldType.TEXT, "UK", true, 4L),
    GeobaseUseShortestRoute(GisParameter.use_shortest_route, MapProviderType.geobase, BOOLEAN, "true", true, 5L),
    GeobaseEnableLog(GisParameter.enableLogging, MapProviderType.geobase, GISFieldType.BOOLEAN, "false", true, 6L),
    GeobaseEnableCache(GisParameter.enableCache, MapProviderType.geobase, GISFieldType.BOOLEAN, "true", true, 7L),
    GeobaseDisablePersistenceCache(GisParameter.disablePersistenceCache, MapProviderType.geobase, GISFieldType.BOOLEAN, "false", true, 8L),
    GeobaseCacheStorageTime(GisParameter.cacheStorageTime, MapProviderType.geobase, GISFieldType.INTEGER, "30", true, 12L, false),
    GeobaseSearchFieldAddressFormatHint(GisParameter.searchFieldAddressFormatHint, MapProviderType.geobase, GISFieldType.TEXT,
            "<Street> <House>, <City>, <Postcode>", false, 8L),
    GeobaseUseMultiplePointsRouting(GisParameter.useMultiplePointsRouting, MapProviderType.geobase, GISFieldType.BOOLEAN, "true", false, 9L, true),
    GeobaseEnableBatchRouteRequests(GisParameter.enableBatchRouteRequests, MapProviderType.geobase, GISFieldType.BOOLEAN, "true", false, 10L),
    GeobaseTimeoutOnRequestForSingleRoute(GisParameter.timeout_on_request_for_single_route, MapProviderType.geobase, GISFieldType.INTEGER, "60", true, 13L),
    GeobaseTimeoutOnRequestForSomeRoutes(GisParameter.timeout_on_request_for_some_routes, MapProviderType.geobase, GISFieldType.INTEGER, "180", true, 14L),
    GeobaseRoutesBatchSizeForDistanceCalculation(GisParameter.routes_batch_size_for_distance_calculation, MapProviderType.geobase, GISFieldType.INTEGER, "30", true, 15L),
    GeobaseAttemptsCountForSingleDistanceCalculation(GisParameter.attempts_count_for_single_distance_calculation, MapProviderType.geobase, GISFieldType.INTEGER, "3", false, 16L),
    GeobaseAttemptsCountForBatchDistanceCalculation(GisParameter.attempts_count_for_batch_distance_calculation, MapProviderType.geobase, GISFieldType.INTEGER, "3", false, 17L),
    GeobaseEnableSingleAttemptsForDistanceCalculation(GisParameter.enable_single_attempts_for_distance_calculation, MapProviderType.geobase, GISFieldType.BOOLEAN, "true", false, 18L),
    GeobaseRoutingProfile(GisParameter.routing_profile, MapProviderType.geobase, TEXT, "", false, 19L),
    GeobaseCorrectionFactor(GisParameter.correctionFactor, MapProviderType.geobase, GISFieldType.FLOAT, "1", true, false, 20L),
    GeobaseVehicleType(GisParameter.default_vehicle_type, MapProviderType.geobase, GISFieldType.LIST, true, VehicleType.Default.name(), VehicleType.asStringList(), 21L),
    GeobaseRestrictedRoads(GisParameter.restricted_roads, MapProviderType.geobase, TEXT, "", false, 22L),
    GeobasePersistedCacheMessageSize(GisParameter.persisted_cache_message_size, MapProviderType.geobase, INTEGER, "100", true, 23L),
    GeobaseUseTollRoads(GisParameter.use_toll_roads, MapProviderType.geobase, BOOLEAN, "true", true, false, 24L);

    private String name;
    private String label;
    private Long order;
    private GISFieldType type;
    private String defaultValue;
    private boolean required;
    private String groupName;
    private boolean important = true;
    private boolean readOnly = false;
    private List<String> variants;
    private String tab = "GIS";

    private GeobaseAttribute(GisParameter parameter, MapProviderType providerType, GISFieldType type,
                             Boolean required, String defaultValue, List<String> variants, Long order) {
        this.name = parameter.withProvider(providerType.name());
        this.type = type;
        this.label = parameter.getLabel();
        this.required = required;
        this.defaultValue = defaultValue;
        this.groupName = providerType.getLabel();
        this.variants = variants;
        this.order = order;
    }

    private GeobaseAttribute(GisParameter parameter, MapProviderType providerType, GISFieldType type,
                             String defaultValue, boolean required, Long order, boolean readOnly) {
        this(parameter, providerType, type, defaultValue, required, order);
        this.readOnly = readOnly;
    }

    private GeobaseAttribute(GisParameter parameter, MapProviderType providerType, GISFieldType type,
                             String defaultValue, boolean required, Long order) {
        this.name = parameter.withProvider(providerType.name());
        this.label = parameter.getLabel();
        this.type = type;
        this.defaultValue = defaultValue;
        this.groupName = providerType.getLabel();
        this.required = required;
        this.order = order;
    }

    private GeobaseAttribute(GisParameter parameter, MapProviderType providerType, GISFieldType type,
                             String defaultValue, boolean required, boolean important, Long order) {
        this.name = parameter.withProvider(providerType.name());
        this.label = parameter.getLabel();
        this.type = type;
        this.defaultValue = defaultValue;
        this.groupName = providerType.getLabel();
        this.required = required;
        this.order = order;
        this.important = important;
    }

    public boolean isImportant() {
        return important;
    }

    public String getName() {
        return name;
    }

    public GISFieldType getType() {
        return type;
    }

    public String getDefaultValue() {
        return defaultValue;
    }

    public Boolean getMandatory() {
        return required;
    }

    public String getGroup() {
        return groupName;
    }

    public String getLabel() {
        return label;
    }

    public Long getOrder() {
        return order;
    }

    public String getTab() {
        return tab;
    }

    public boolean isReadOnly() {
        return readOnly;
    }

    public List<String> getVariants() {
        return variants;
    }

}
